package com.starbaba.system.index.dao;

import java.util.ArrayList;
import java.util.List;

import com.starbaba.core.hibernate.DAOFactory;
import com.starbaba.core.hibernate.HibernateDAO;
import com.starbaba.core.hibernate.Strategy;
import com.starbaba.system.user.model.UserVO;
import com.starbaba.system.usergroup.model.UsergroupComidVO;


@SuppressWarnings({"serial","unchecked"})
public class QueryUserGroupComidStrategy implements Strategy {
	private UserVO userVO;

	public QueryUserGroupComidStrategy(UserVO userVO) {
		super();
		this.userVO = userVO;
	}

	@Override
	public Object process() throws Exception {
		HibernateDAO queryDao = DAOFactory.getInstance().createHibernateDAO(UsergroupComidVO.class);
		
		StringBuffer hql = new StringBuffer();	
		hql.append(" SELECT groupid FROM ");
		hql.append(UsergroupComidVO.class.getName()).append(" as ug ");
		hql.append(" where ug.comid = ? and groupid in (1,17) ");
		List<Long> groupComIdList = (List<Long>)queryDao.findByHQL(hql.toString(), new Object[]{userVO.getComid()});
		if(null == groupComIdList) {
			groupComIdList = new ArrayList<Long>();
		}
		return groupComIdList;
	}

	/**
	 * @return userVO
	 */

	public UserVO getUserVO() {
		return userVO;
	}

	/**
	 * @param userVO
	 *            the userVO to set
	 */
	public void setUserVO(UserVO userVO) {
		this.userVO = userVO;
	}

}
